import $ from "jquery";
import {url} from "../../util/config";
import login from "../login";
import {message} from "antd";

function getNewLogin(items) {
    return subStatus(items)
}

export default function subStatus(items) {
    let token = localStorage.getItem("token")
    let status;
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`subscribe/status?type=${items.type}&id=${items.id}`,
        type: 'get',
        success: function (result) {
            status = result.result
            if(status=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(items)
            }
        },
        error:function (error) {
            status = "error"
            message.error("请求异常");
        }
    })
    return status
}
